#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from flask_apscheduler import APScheduler
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from flask_smorest import Api
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy(session_options={"autoflush": False})
api = Api()
scheduler = APScheduler()


def db_extends(app):
    """ 加载迁移命令 """
    manager = Manager(app)
    db.init_app(app)

    api.init_app(app)

    scheduler.init_app(app)
    scheduler.start()

    # 创建数据库迁移命令
    Migrate(app, db)
    manager.add_command('db', MigrateCommand)
    return manager

